import { createRouter, createWebHashHistory } from "vue-router"
import HomeView from "../views/HomeView.vue"

// 2. 创建一个 数组用于一会创建路由规则
const routes = [
    {
        path: "/",
        name: "home",
        component: HomeView,
        children: [
            {
                path: "/shouye",
                name: "shouye",
                // 懒加载, 只有在用到当前组件的时候才会加载
                component: () => import("../views/Home.vue"),
            },
            {
                path: "user",
                name: "user",
                label: "用户管理列表",
                component: () => import("@/views/user/ManagerIndexView.vue"),
                children: [
                    {
                        path: "managerlist",
                        name: "managerlist",
                        label: "管理员列表",
                        component: () =>
                            import("@/views/user/ManagerListView.vue"),
                    },
                    {
                        path: "userlist",
                        name: "userlist",
                        label: "用户列表",
                        component: () =>
                            import("@/views/user/UserListView.vue"),
                    },
                ],
            },
            {
                path: "pro",
                name: "pro",
                label: "商品列表管理",
                component: () => import("@/views/pro/ProIndexView.vue"),
                children: [
                    {
                        path: "prolist",
                        name: "prolist",
                        label: "商品列表",
                        component: () => import("@/views/pro/ProListView.vue"),
                    },
                    {
                        path: "addpro",
                        name: "addpro",
                        label: "添加商品",
                        component: () => import("@/views/pro/AddProView.vue"),
                    },
                ],
            },
            {
                path: "sales",
                name: "sales",
                label: "商品列表管理",
                component: () => import("@/views/sales/SalesIndexView.vue"),
                children: [
                    {
                        path: "line",
                        name: "line",
                        label: "折线图",
                        component: () => import("@/views/sales/LineView.vue"),
                    },
                    {
                        path: "bar",
                        name: "bar",
                        label: "柱状图",
                        component: () => import("@/views/sales/BarView.vue"),
                    },
                    {
                        path: "pie",
                        name: "pie",
                        label: "饼状图",
                        component: () => import("@/views/sales/PieView.vue"),
                    },
                ],
            },
            {
                path: "center",
                name: "center",
                label: "商品列表管理",
                component: () => import("@/views/center/CenterIndexView.vue"),
                children: [
                    {
                        path: "person",
                        name: "person",
                        label: "个人信息",
                        component: () =>
                            import("@/views/center/CenterView.vue"),
                    },
                ],
            },
        ],
    },
    {
        path: "/login",
        name: "login",
        // 懒加载, 只有在用到当前组件的时候才会加载
        component: () => import("../views/LoginView.vue"),
    },
    {
        path: "/zhuce",
        name: "zhuce",
        // 懒加载, 只有在用到当前组件的时候才会加载
        component: () => import("../views/ZhuceView.vue"),
    },
]

const router = createRouter({
    // history: createWebHistory(import.meta.env.BASE_URL),
    history: createWebHashHistory(import.meta.env.BASE_URL),
    routes,
})

// 3. 导出当前路由规则
export default router
